package com.csx.ops.web.base;

import com.yh.csx.bsf.core.util.PropertyUtils;
import com.yh.csx.bsf.core.util.WebUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class User implements Serializable {

    public static User getCurrent() {
        Object u = WebUtils.getRequest().getSession().getAttribute("Current");
        if (u == null) {
            return null;
        } else {
            return (User) u;
        }
    }

    public static void setCurrent(User value) {
        WebUtils.getRequest().getSession().setAttribute("Current", value);
    }


    public boolean isAdmin() {
        Object admins = PropertyUtils.getProperty("bsf.flow.user.admin");
        if (admins == null || StringUtils.isBlank(admins.toString())) {
            return false;
        } else {
            String[] admin = admins.toString().split(",");
            for (int i = 0; i < admin.length; i++) {
                if (admin[i].equals(this.getUserno())) {
                    return true;
                }
            }
        }
        return false;
    }

    private String username;
    private String userno;
    private String email;
    private String telephone;


}
